#include <stdio.h>
#include <stdlib.h>

void print_arr(int* arr, int len) {
    printf("[");
    for (int i = 0; i < len; ++i) {
        printf(i == len - 1 ? "%d" : "%d, ", arr[i]);
    }
    printf("]\n");
}

// my_memmove
void* my_memmove(void* dest, const void* src, size_t size) {
    char* d = (char*)dest;
    char* s = (char*)src;
    if (dest < src) {
        while (size-- > 0) {
            *d++ = *s++;
        }
    } else {
        d = d + size - 1;
        s = s + size - 1;
        while (size-- > 0) {
            *d-- = *s--;
        }
    }
    return dest;
}

void test1() {
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int len = sizeof(arr) / sizeof(*arr);
    my_memmove(arr, arr + 2, 20);
    print_arr(arr, len);
}

//

void test8() {
    int a = 0x1;
    char* p = (char*)&a;
    if (*p == 1) {
        printf("1\n");
    } else {
        printf("0\n");
    }
}

int my_itoa(const char* str) {
    int ret = 0;
    while (*str != '\0') {
        ret = ret * 10 + *str - '0';
        str++;
    }
    return ret;
}

void test9() {
    char* a = "1234";
    int x = atoi(a);
    int y = my_itoa(a);
    printf("%d\n", x);
    printf("%d\n", y);
}

int main() {
    test1();
    printf("======================\n");
    test8();
    printf("======================\n");
    test9();
    return 0;
}